var app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    imageUrl:app.globalData.imageUrl,
    "tabActive": "menu",
    "itemActive": "hot",
    "emptyCart": false,
    "reachMinPrice": true,
    "hiddenModal": "none",
    "hiddenMask": "none",
    "hiddenCart": "none",
    "foods": {
      "id1": {
        "name": "芝士鸡排便当",
        "desc": "芝士搭配炸鸡排，再加上浓浓",
        "sales": "50",
        "stars": "35",
        "price": "17.9",
        "pic": "food2.png",
        "cart": 0,
        "hasChoose": true,
        "规格": ["标准", "大份", "小份"],
        "加料": ["芝士", "培根", "火腿"]
      },
      "id2": {
        "name": "卡通定制便当",
        "desc": "芝士搭配炸鸡排，再加上浓浓",
        "sales": "38",
        "stars": "9",
        "price": "15.9",
        "pic": "food1.png",
        "cart": 0,
        "hasChoose": false
      },
      "id3": {
        "name": "创意蔬菜便当",
        "desc": "鸡蛋搭配面包，再加上新鲜的蔬",
        "sales": "40",
        "stars": "20",
        "price": "19.9",
        "pic": "food3.png",
        "cart": 1,
        "hasChoose": true,
        "规格": ["标准", "大份", "小份"],
        "加料": ["芝士", "培根", "火腿"]
      }
    },
    "menus": {
      "hot": {
        "id": "hot",
        "category": "热销",
        "menu": ["id1"]
      },
      "menu2": {
        "id": "menu2",
        "category": "超人气便当套餐",
        "menu": ["id2"]
      },
      "menu3": {
        "id": "menu3",
        "category": "日式便当",
        "menu": ["id3"]
      },
      "menu4": {
        "id": "menu4",
        "category": "韩式便当",
        "menu": ["id2", "id3"]
      }
      ,
      "menu5": {
        "id": "menu5",
        "category": "创意便当",
        "menu": ["id2"]
      },
      "menu6": {
        "id": "menu6",
        "category": "个性便当",
        "menu": ["id3"]
      },
      "menu7": {
        "id": "menu7",
        "category": "定制便当",
        "menu": ["id2", "id3"]
      }
    }
  },
  /**
   * 加入购物车
   */
  minusCart: function (e) {
    var num = e.currentTarget.dataset.num - 1;
    var cartNum = "foods." + e.currentTarget.dataset.id + ".cart";
    console.log(num);
    this.setData({
      [cartNum]: num
    })
  },
  //弹出选择框  
  showModal: function () {
    this.setData({
      hiddenModal: 'fixed',
      hiddenMask: 'fixed'
    })
  },
  //关闭弹窗  
  cancel: function () {
    this.setData({
      hiddenModal: 'none',
      hiddenMask: 'none',
      hiddenCart: 'none'
    });
  },
  //展示购物车
  showCart: function () {
    var displayValue = 'fixed';
    if (this.data.hiddenCart == 'fixed') {
      displayValue = 'none';
    }
    this.setData({
      hiddenCart: displayValue,
      hiddenMask: displayValue
    })
  },
  addCart: function (e) {
    //添加购物车
    var num = e.currentTarget.dataset.num + 1;
    var cartNum = "foods." + e.currentTarget.dataset.id + ".cart";
    console.log(num);
    this.setData({
      [cartNum]: num
    })
  },
  /**
   * 去结算
   */
  showOrder: function (e) {
    wx.navigateTo({
      url: '/pages/demo1/create-order/create-order'
    })
  },
  /**
   * 分类选择
   */
  skipMenu: function (e) {
    var id = e.currentTarget.id.substr(4);
    this.setData({
      itemActive: id
    });
  },
  /**
  * 滚动
  */
  scroll: function (e) {

  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})